package com.example.reggie.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.example.reggie.Filter.LoginCheckFilter;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

@Slf4j
@Component
public class MyMetaObjecthandler implements MetaObjectHandler {


    @Autowired
    private BaseContext baseContext;
    /**
     * 插入操作，自动填充
     * @param metaObject
     */

    @Override
    public void insertFill(MetaObject metaObject) {


        /*创建时间和更新时间*/
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime",LocalDateTime.now());
        /*创建人和修改人*/
//        metaObject.setValue("createUser",new Long(1));
        metaObject.setValue("createUser", baseContext.getThreadLocal());
        metaObject.setValue("updateUser",baseContext.getThreadLocal());


    }
    /**
     * 更新操作，自动填充
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        /*修改时间*/
        metaObject.setValue("updateTime",LocalDateTime.now());
        /*修改人*/
        metaObject.setValue("updateUser",baseContext.getThreadLocal());

    }
}
